package top.hmtools.beans;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 行政划区地名描述实体类
 * @author Jianghaibo
 *
 */
public class DivisionBean implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = -8490152017395790355L;

    /**
     * 行政代号（编码）
     */
    protected String code;
    
    /**
     * 省份（直辖市）名称
     */
    protected String province;
    
    /**
     * 市
     */
    protected String city;
    
    /**
     * 区（县）
     */
    protected String district;
    
    /**
     * 上级行政区代号
     */
    protected String parentCode;
    
    /**
     * 下级行政区集合
     */
    protected Map<String,DivisionBean> children = new HashMap<String, DivisionBean>();;

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the province
     */
    public String getProvince() {
        return province;
    }

    /**
     * @param province the province to set
     */
    public void setProvince(String province) {
        this.province = province;
    }

    /**
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * @param city the city to set
     */
    public void setCity(String city) {
        this.city = city;
    }

    /**
     * @return the district
     */
    public String getDistrict() {
        return district;
    }

    /**
     * @param district the district to set
     */
    public void setDistrict(String district) {
        this.district = district;
    }
    
    

    /**
     * @return the parentCode
     */
    public String getParentCode() {
        return parentCode;
    }

    /**
     * @param parentCode the parentCode to set
     */
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    /**
     * @return the children
     */
    public Map<String, DivisionBean> getChildren() {
        return children;
    }

    /**
     * 添加一个下级行政区域信息
     * @param children the children to set
     */
    public void addChildren(DivisionBean... children) {
        for(DivisionBean bean:children){
            this.children.put(bean.getCode(), bean);
        }
    }

    /**
     * 方法说明
     * 输入参数说明
     * 输出参数说明
     */
    @Override
    public String toString() {
        StringBuffer result = new StringBuffer();
        if(!this.isBlank(code)){
            result.append(code);
            result.append(" ");
        }
        if(!this.isBlank(this.province)){
            result.append(this.province);
            result.append(" ");
        }
        if(!this.isBlank(city)){
            result.append(this.city);
            result.append(" ");
        }
        if(!this.isBlank(district)){
            result.append(this.district);
            result.append(" ");
        }
        return result.toString();
    }
    
    private boolean isBlank(String str){
        if(str==null || "".equals(str)){
            return true;
        }else{
            return false;
        }
    }
    
    
}
